import type { App } from 'vue';

import ConfirmContainer from './ConfirmContainer.vue';
import { useConfirmStore } from './store';
import type { ConfirmAPI } from './types';

const ConfirmPlugin = {
  install(app: App) {
    // 注册组件
    app.component('ConfirmContainer', ConfirmContainer);

    // 创建confirm API
    const confirmStore = useConfirmStore();
    const confirmAPI: ConfirmAPI = {
      show: confirmStore.showConfirm,
      info: confirmStore.info,
      warning: confirmStore.warning,
      error: confirmStore.error,
      success: confirmStore.success
    };

    // 添加到全局属性
    app.config.globalProperties.$confirm = confirmAPI;

    // 提供给组合式API使用
    app.provide('$confirm', confirmAPI);
  }
};

export default ConfirmPlugin;
export { useConfirmStore };
export type { ConfirmAPI, ConfirmInstance, ConfirmOptions } from './types';
